-
Notifications
You must be signed in to change notification settings - Fork 801
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[#674, #675] Mitigate performance regression by filtering restricted registry collections #680
Conversation
Signed-off-by: Pavel <pavel@lexyr.com>
ea2b225
to
009d885
Compare
py2.7 passes locally. What do the logs say on the CI? |
You can use a skipIf and import the mock only for the test such as done in https://github.com/prometheus/client_python/blob/master/tests/openmetrics/test_parser.py#L492. |
Signed-off-by: Pavel <pavel@lexyr.com>
Aha. That worked - thank you! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This approach looks good to me, and I appreciate the test you added. I will give some time for @brian-brazil to review as well.
prometheus_client/registry.py
Outdated
m = metric._restricted_metric(self._name_set) | ||
if m: | ||
yield m | ||
names = copy.copy(self._name_set) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this copy here? This set shouldn't be changing after the object is instantiated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trying to do it in the same way collections used to be filtered with target_info. There used to be a set variable that was modified if target_info was found - in order not to change the class field in the same way, we copy it to names
.
prometheus_client/registry.py
Outdated
collectors = set() | ||
with self._registry._lock: | ||
if 'target_info' in names and self._registry._target_info: | ||
yield self._registry._target_info_metric() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it is safe to yield under the lock.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed. Good catch!
Signed-off-by: Pavel <pavel@lexyr.com>
prometheus_client/registry.py
Outdated
with self._registry._lock: | ||
if 'target_info' in names and self._registry._target_info: | ||
yield_target_info = True | ||
names.remove('target_info') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need this, the registry should be preventing this from happening in the first place.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure I understood it right - but done.
prometheus_client/registry.py
Outdated
yield m | ||
names = copy.copy(self._name_set) | ||
collectors = set() | ||
yield_target_info = False |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd have this as the thing to yield, rather than a bool for cleanliness. Also avoids a race.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
Signed-off-by: Pavel <pavel@lexyr.com>
👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the additional review and fixes!
#675 introduces a significant performance regression in restricted registry collecting. This attempts to reduce the regression by re-introducing filter code removed in the previous version.